
$(document).ready(function(){

    disableForm("frmData");
} );

function doChangeSection(para){
    $("#section_id").find('option').remove().end();
    var params =encodeURIComponent("instituteId") + "="+document.getElementById("institute_id").value;
    ajaxPost("?employee/getSectionList", params, function(data) {
			var response =data;
			if (response.status==false) {
				return;
			}
                $('#section_id').append(response);
        $("#section_id").val( para).attr('selected',true);
    });
    reloadGrid();
}
function reloadGrid() {
    var searchCriteriaInstituteId = document.getElementById("institute_id").value;
    var searchCriteriaSectionId = document.getElementById("section_id").value;
    var params =encodeURIComponent("instituteId") + "="+searchCriteriaInstituteId+"&sectionId="+searchCriteriaSectionId;
    ajaxPost("?tld/getEmpCardList", params, function(data) {
			var response =JSON.parse(data);
			if (response.status==false) {
				return;
			}
            $("#formBody").html("" ) ;
            $("#formBody").html(response.tableHtml) ;
            $("#messagePanel").removeClass();
             $("#messagePanel").html("" ) ;
              disableForm("frmData");
             handleDefaultButtons("gridclick");
		});
}
function edit(){
    enableForm("frmData");
    handleDefaultButtons("edit");
}
function clearBt(){
    $("#messagePanel").removeClass();
    $("#messagePanel").html("" ) ;
    $("#formBody").html("" ) ;
    initialize();
}
function save(){
        var params = serializeForm("frmData")+"&" + encodeURIComponent("instituteId") + "="+$("#institute_id").val()+"&" + encodeURIComponent("sectionId") + "="+$("#section_id").val() ;
        ajaxPost("?tld/updateEmpCardList", params, function(data) {
			var response =JSON.parse(data);
			if (response.status==false) {
				return;
			}
            $("#messagePanel").removeClass();
            $("#messagePanel").addClass(response.type);
            $("#messagePanel").html(response.message ) ;


			initialize();
           // reloadGrid();

		});


    handleDefaultButtons("save");
}
function validateCode(item){
      //  var reg = /^[0-9]{9}[vVxX]$/;
       // if (reg.test(nic.val())) {
            //test with db
            var input = document.getElementsByName(item).id ;
            var params =encodeURIComponent("code") + "="+item.value;
            ajaxPost("?employee/checkTldCode", params, function(data) {
			var response =JSON.parse(data);
			if (response.status==false) {
				return;
			}
             if(response.message){                
                $("#msgTest").removeClass('error');
                 $("#msgTest").html("" ) ;
			    return true;
             }else{

                  $("#msgTest").addClass('error');
                 $("#msgTest").html("Invalid ID: "+item.value ) ;
			    return false;
             }
		});

       /* }else{
            nic.addClass("errorField");
			nicInfo.text("Please enter valid NIC number");
			nicInfo.addClass("errorField");
			return false;
        }*/
	}

function closePage(){
    window.location.href="?home";
}
function initialize(fnAfterInit) {
    disableForm("frmData");
    handleDefaultButtons("gridclick");
}
function onLoad(){
     initialize();
     enforcePrivileges();
   // reloadGrid();
}
onLoad();